from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import user_passes_test
from books.models import Books
from books.models import News


def main_page(request):    
    books = Books.objects.all()[:3]    
    return render_to_response("main_page.html", {'books': books})

def news(request):
    news = News.objects.all()[:5]
    return render_to_response("news.html", {"news": news})

def about(request):
    return render_to_response("about.html")

def contacts(request):
    return render_to_response("contacts.html")

def user_is_admin(user):
    return user.is_authenticated() and user.has_perm('auth.is_admin')

#@login_required(login_url="/login")
@user_passes_test(user_is_admin, login_url="/login")
def test(request):
    return render_to_response("test.html")